<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>角色添加</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/darkBlue.css"/>
</head>
<body>
<div class="page-content-wrap">
    <form class="layui-form">
        <div class="layui-tab" style="margin:0 50px 70px 30px;">
            <div class="layui-tab-content">
                <div class="layui-tab-item"></div>
                <div class="layui-tab-item layui-show">
                    <input type="hidden" class="form-control id" id="id" name="id" value="${sysRole.id}"/>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;角色名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="roleName" lay-verify="required" placeholder="请输入角色名称" value="${sysRole.roleName}" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;权限字符：</label>
                        <div class="layui-input-block">
                            <input type="text" name="permission" lay-verify="required" placeholder="请输入权限字符" value="${sysRole.permission}" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;状态：</label>
                        <div class="layui-input-block">
                            <select name="status" id="status"></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;排序：</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" lay-verify="required" placeholder="请输入排序" value="${sysRole.sort}" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;菜单权限：</label>
                        <div class="layui-input-block h240 overauto scrollbar">
                            <input type="hidden" name="orgId" id="orgId" value="${sysRole.orgId}"/>
                            <ul id="menu" class="dtree" data-id="0" data-selector-type="mult"></ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <div class="">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'dialog', 'baseutil', 'dtreeUtil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            dialog = layui.dialog,
            baseutil = layui.baseutil,
            dtreeUtil = layui.dtreeUtil;

        var page = layui.page;
        page.initDict("base_status", function (dictData) {
            page.showDict($("#status"), page.aceeptDictContentList(dictData, "base_status"), "", '${sysRole.status}');
        });

        var menuIds = '${sysRole.menuIds}';
        var dTree = dtreeUtil.pageDtree("#menu", "/sysMenu/dTreeList", true, function (data, obj) {
            if (!isBlank(menuIds)) {
                dtreeUtil.chooseDataInit("menu", menuIds);
            }
            dTree.closeAllNode();
        });

        //监听提交
        form.on('submit(submitBtn)', function (data) {
            dtreeUtil.getCheckbarNodesParam("menu", function (params) {
                if (params.length === 0) {
                    dialog.msg("请至少选择一个权限");
                    return false;
                }
                var ids = [];
                for (var key in params) {
                    var param = params[key];
                    ids.push(param.nodeId);
                }
                data.field.menuIds = ids.join(",");
                baseutil.AjaxPostMark("/sysRole/addOrUpdate", data.field, function (result) {
                    dialog.msg(result.data);
                    $("#save").click();
                });
            });
            return false;
        });
    });
</script>
</body>
</html>